package club.jdiy.core.convert;

import java.math.BigDecimal;
import java.math.BigInteger;

class FloatConverter extends NumberConverter<Float> {
    public FloatConverter(Float source) {
        super(source);
    }

    @Override
    public Float getSource() {
        return source;
    }

    @Override
    public Boolean getBoolean() {
        return source != 0;
    }

    @Override
    public Byte getByte() {
        if (source > Byte.MAX_VALUE || source < Byte.MIN_VALUE) {
            throw __throw(Byte.class);
        } else {
            return source.byteValue();
        }
    }

    @Override
    public Short getShort() {
        if (source > Short.MAX_VALUE || source < Short.MIN_VALUE) {
            throw __throw(Short.class);
        } else {
            return source.shortValue();
        }
    }

    @Override
    public Integer getInteger() {
        return Math.round(source);
    }

    @Override
    public Long getLong() {
        return getInteger().longValue();
    }

    @Override
    public Float getFloat() {
        return getSource();
    }

    @Override
    public BigDecimal getBigDecimal() {
        return BigDecimal.valueOf(source);
    }

    @Override
    public BigInteger getBigInteger() {
        return BigInteger.valueOf(getLong());
    }
}
